import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// import { transpileModule } from 'typescript'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },

  //服务器
  server: {
    port: 3000, //修改端口
    open: true, //自动打开浏览器

    // 地址：http://localhost:3000/ftyyptapi/user/login
    // 发生代理：http://123.56.141.187:82/ftyyptapi/user/login

    // 地址：http://localhost:3000/ftyyptapi/user/login
    // =>http://123.56.141.187:82/ftyyptapi/user/login
    // 真实的接口：http://123.56.141.187:82/user/login
    // 路径重写：rewrite: (path) => path.replace(/^\/ftyyptapi/, ''),

    proxy: {
      '/ftyyptapi': {
        target: 'http://123.56.141.187:82',
      },
    },
  },

  css: {
    preprocessorOptions: {
      // define global scss variable
      scss: {
        additionalData: `
				@import '@/styles/variables.scss';
			`,
      },
    },
  },
})
